<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>LCOV - qgetopt test coverage - object/optionManager/optSwitch.cpp</title>
  <link rel="stylesheet" type="text/css" href="../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LTP GCOV extension - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
        <tr>
          <td class="headerItem" width="20%">Current&nbsp;view:</td>
          <td class="headerValue" width="80%" colspan=4><a href="../../index.html">directory</a> - <a href="index.html">object/optionManager</a> - optSwitch.cpp</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Test:</td>
          <td class="headerValue" width="80%" colspan=4>qgetopt test coverage</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Date:</td>
          <td class="headerValue" width="20%">2009-08-26</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Instrumented&nbsp;lines:</td>
          <td class="headerValue" width="20%">56</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Code&nbsp;covered:</td>
          <td class="headerValue" width="20%">92.9 %</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Executed&nbsp;lines:</td>
          <td class="headerValue" width="20%">52</td>
        </tr>
        </table>
      </td>
    </tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td><pre class="source">
<span class="lineNum">       1 </span>                : /***************************************************************************
<span class="lineNum">       2 </span>                :  *   This program is free software; you can redistribute it and/or modify  *
<span class="lineNum">       3 </span>                :  *   it under the terms of the GNU General Public License as published by  *
<span class="lineNum">       4 </span>                :  *   the Free Software Foundation; either version 2 of the License, or     *
<span class="lineNum">       5 </span>                :  *   (at your option) any later version.                                   *
<span class="lineNum">       6 </span>                :  *                                                                         *
<span class="lineNum">       7 </span>                :  *   This program is distributed in the hope that it will be useful,       *
<span class="lineNum">       8 </span>                :  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
<span class="lineNum">       9 </span>                :  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
<span class="lineNum">      10 </span>                :  *   GNU General Public License for more details.                          *
<span class="lineNum">      11 </span>                :  *                                                                         *
<span class="lineNum">      12 </span>                :  *   You should have received a copy of the GNU General Public License     *
<span class="lineNum">      13 </span>                :  *   along with this program; if not, write to the                         *
<span class="lineNum">      14 </span>                :  *   Free Software Foundation, Inc.,                                       *
<span class="lineNum">      15 </span>                :  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
<span class="lineNum">      16 </span>                :  ***************************************************************************
<span class="lineNum">      17 </span>                :  * File Name: optSwitch.cpp                                                *
<span class="lineNum">      18 </span>                :  * Author:    Graeme                                                       *
<span class="lineNum">      19 </span>                :  * Class:     OptSwitch                                                    *
<span class="lineNum">      20 </span>                :  * Copyright (C) 2008  Graeme Foster                                       *
<span class="lineNum">      21 </span>                :  **************************************************************************/
<span class="lineNum">      22 </span>                : #include &quot;optSwitch.h&quot;
<span class="lineNum">      23 </span>                : /*****************************************************************************
<span class="lineNum">      24 </span>                :  * Private Methods
<span class="lineNum">      25 </span>                :  *****************************************************************************/
<span class="lineNum">      26 </span>                : 
<span class="lineNum">      27 </span>                : /*! \internal This will instantiate an instance of the OptSwitch class.
<span class="lineNum">      28 </span>                :   * This initialises all the details of the switch. Because it is private
<span class="lineNum">      29 </span>                :   * instances can only be created by friend a class, which is OptManager.
<span class="lineNum">      30 </span>                :   */
<span class="lineNum">      31 </span><span class="lineCov">            114 : OptSwitch::OptSwitch(QChar abbrev, QString fullName, QString args, ActionFuncPtr actionMethod, CloseFuncPtr exitMethod, switchStyle style)</span>
<span class="lineNum">      32 </span>                : {
<span class="lineNum">      33 </span><span class="lineCov">            114 :    _shortName = abbrev.isLetterOrNumber()?abbrev:QChar::Null;</span>
<span class="lineNum">      34 </span><span class="lineCov">            114 :    _longName = fullName;</span>
<span class="lineNum">      35 </span><span class="lineCov">            114 :    _description = QString();</span>
<span class="lineNum">      36 </span><span class="lineCov">            114 :    _actualArgList.clear();</span>
<span class="lineNum">      37 </span><span class="lineCov">            114 :    QStringList argParts = args.split(&quot; &quot;, QString::SkipEmptyParts);</span>
<span class="lineNum">      38 </span><span class="lineCov">            187 :    for (int i = 0; i &lt; argParts.size(); ++i)</span>
<span class="lineNum">      39 </span>                :    {
<span class="lineNum">      40 </span><span class="lineCov">             73 :       OptArgument * oa = new OptArgument(argParts[i]);</span>
<span class="lineNum">      41 </span><span class="lineCov">             73 :       if (oa-&gt;isMandatory())</span>
<span class="lineNum">      42 </span><span class="lineCov">             48 :          _mandatoryArgList.append(oa);</span>
<span class="lineNum">      43 </span>                :       else
<span class="lineNum">      44 </span><span class="lineCov">             25 :          _optionalArgList.append(oa);</span>
<span class="lineNum">      45 </span>                :    }
<span class="lineNum">      46 </span><span class="lineCov">            114 :    _actionFn = actionMethod;</span>
<span class="lineNum">      47 </span><span class="lineCov">            114 :    _closeFn = exitMethod;</span>
<span class="lineNum">      48 </span><span class="lineCov">            114 :    _style = style;</span>
<span class="lineNum">      49 </span><span class="lineCov">            114 : }</span>
<span class="lineNum">      50 </span>                : 
<span class="lineNum">      51 </span>                : /*! \internal returns a string with the details of the switch
<span class="lineNum">      52 </span>                :  * it will display the short name,if one exists otherwise the long name
<span class="lineNum">      53 </span>                :  * followed by the details of the arguments that are supported
<span class="lineNum">      54 </span>                :  */
<span class="lineNum">      55 </span><span class="lineCov">              4 : QString OptSwitch::brief()</span>
<span class="lineNum">      56 </span>                : {
<span class="lineNum">      57 </span><span class="lineCov">              4 :    QString msg;</span>
<span class="lineNum">      58 </span><span class="lineCov">              4 :    if (_shortName.isNull())</span>
<span class="lineNum">      59 </span><span class="lineCov">              2 :       msg = &quot;--&quot; + _longName;</span>
<span class="lineNum">      60 </span>                :    else
<span class="lineNum">      61 </span><span class="lineCov">              2 :       msg = QString(&quot; -&quot;) + _shortName;</span>
<span class="lineNum">      62 </span><span class="lineCov">              4 :    msg += fullArgList();</span>
<span class="lineNum">      63 </span><span class="lineNoCov">              0 :    return msg;</span>
<span class="lineNum">      64 </span>                : }
<span class="lineNum">      65 </span>                : 
<span class="lineNum">      66 </span>                : /*! \internal returns a string with the details of the switch
<span class="lineNum">      67 </span>                :  * it will display the short name, if one exists, then the long name
<span class="lineNum">      68 </span>                :  * followed by the details of the arguments that are supported
<span class="lineNum">      69 </span>                :  */
<span class="lineNum">      70 </span><span class="lineCov">             15 : QString OptSwitch::help()</span>
<span class="lineNum">      71 </span>                : {
<span class="lineNum">      72 </span><span class="lineCov">             15 :    QString msg;</span>
<span class="lineNum">      73 </span><span class="lineCov">             15 :    if (_shortName.isNull())</span>
<span class="lineNum">      74 </span><span class="lineCov">              3 :       msg = &quot;    &quot;;</span>
<span class="lineNum">      75 </span>                :    else
<span class="lineNum">      76 </span><span class="lineCov">             12 :       msg = QString(&quot;  -&quot;) + _shortName;</span>
<span class="lineNum">      77 </span><span class="lineCov">             15 :    msg += &quot; --&quot; + _longName;</span>
<span class="lineNum">      78 </span><span class="lineCov">             15 :    msg += fullArgList();</span>
<span class="lineNum">      79 </span><span class="lineCov">             15 :    if (!_description.isEmpty())</span>
<span class="lineNum">      80 </span>                :    {
<span class="lineNum">      81 </span><span class="lineCov">             15 :       msg += &quot;\n&quot; + format80(_description) + &quot;\n&quot;;</span>
<span class="lineNum">      82 </span>                :    }
<span class="lineNum">      83 </span><span class="lineNoCov">              0 :    return msg;</span>
<span class="lineNum">      84 </span>                : }
<span class="lineNum">      85 </span>                : 
<span class="lineNum">      86 </span>                : /*! \internal returns a string with the details of the switch
<span class="lineNum">      87 </span>                :  * it will display the long name followed by the arguments that are supported
<span class="lineNum">      88 </span>                :  */
<span class="lineNum">      89 </span><span class="lineCov">              7 : QString OptSwitch::dump()</span>
<span class="lineNum">      90 </span>                : {
<span class="lineNum">      91 </span><span class="lineCov">              7 :    QString details = _longName + &quot;:&quot;;</span>
<span class="lineNum">      92 </span><span class="lineCov">             12 :    for (int i = 0; i &lt; _actualArgList.size(); ++i)</span>
<span class="lineNum">      93 </span>                :    {
<span class="lineNum">      94 </span><span class="lineCov">              5 :       details += &quot; &quot; + _actualArgList[i];</span>
<span class="lineNum">      95 </span>                :    }
<span class="lineNum">      96 </span><span class="lineNoCov">              0 :    return details;</span>
<span class="lineNum">      97 </span>                : }
<span class="lineNum">      98 </span>                : 
<span class="lineNum">      99 </span>                : /*! \internal returns a string with the details of the mandatory
<span class="lineNum">     100 </span>                :  * and optional arguments that this switch supports
<span class="lineNum">     101 </span>                :  */
<span class="lineNum">     102 </span><span class="lineCov">             19 : QString OptSwitch::fullArgList()</span>
<span class="lineNum">     103 </span>                : {
<span class="lineNum">     104 </span><span class="lineCov">             19 :    QString msg;</span>
<span class="lineNum">     105 </span><span class="lineCov">             31 :    for (int i =0; i &lt; _mandatoryArgList.size(); ++i)</span>
<span class="lineNum">     106 </span>                :    {
<span class="lineNum">     107 </span><span class="lineCov">             12 :       msg += &quot; &quot; + _mandatoryArgList[i]-&gt;help();</span>
<span class="lineNum">     108 </span>                :    }
<span class="lineNum">     109 </span><span class="lineCov">             23 :    for (int i =0; i &lt; _optionalArgList.size(); ++i)</span>
<span class="lineNum">     110 </span>                :    {
<span class="lineNum">     111 </span><span class="lineCov">              4 :       msg += &quot; &quot; + _optionalArgList[i]-&gt;help();</span>
<span class="lineNum">     112 </span>                :    }
<span class="lineNum">     113 </span><span class="lineNoCov">              0 :    return msg;</span>
<span class="lineNum">     114 </span>                : }
<span class="lineNum">     115 </span>                : 
<span class="lineNum">     116 </span>                : /*! \internal This method is used to format the output so that it fits within a screen
<span class="lineNum">     117 </span>                :     80 characters wide and a margin of five characters; both figures are hard-wired.
<span class="lineNum">     118 </span>                :  */
<span class="lineNum">     119 </span><span class="lineCov">             15 : QString OptSwitch::format80(const QString &amp; msg)</span>
<span class="lineNum">     120 </span>                : {
<span class="lineNum">     121 </span><span class="lineCov">             15 :    QStringList list = msg.split(QRegExp(&quot;\\s+&quot;));</span>
<span class="lineNum">     122 </span><span class="lineCov">             15 :    QString margin = &quot;     &quot;;</span>
<span class="lineNum">     123 </span><span class="lineCov">             15 :    QString formatted = margin;</span>
<span class="lineNum">     124 </span><span class="lineCov">             15 :    int size = formatted.size();</span>
<span class="lineNum">     125 </span><span class="lineCov">            236 :    for (int i = 0; i&lt;list.size(); ++i)</span>
<span class="lineNum">     126 </span>                :    {
<span class="lineNum">     127 </span><span class="lineCov">            221 :       if (size + list[i].size() &gt;= 80)</span>
<span class="lineNum">     128 </span>                :       {
<span class="lineNum">     129 </span><span class="lineCov">              6 :          formatted += &quot;\n&quot;+margin+list[i]+&quot; &quot;;</span>
<span class="lineNum">     130 </span><span class="lineCov">              6 :          size = 4 + list[i].size();</span>
<span class="lineNum">     131 </span>                :       }
<span class="lineNum">     132 </span>                :       else
<span class="lineNum">     133 </span>                :       {
<span class="lineNum">     134 </span><span class="lineCov">            215 :          formatted += list[i] + &quot; &quot;;</span>
<span class="lineNum">     135 </span><span class="lineCov">            215 :          size += 1 + list[i].size();</span>
<span class="lineNum">     136 </span>                :       }
<span class="lineNum">     137 </span>                :    }
<span class="lineNum">     138 </span><span class="lineCov">             15 :    return formatted;</span>
<span class="lineNum">     139 </span>                : }
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
  <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LTP GCOV extension version 1.6</a></td></tr>
  </table>
  <br>

</body>
</html>
